package util;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import model.Problem;
import model.Solution;

public class SolutionImporter {
	private Problem problem;
	private String solutionFileName;
	private Solution solution;

	public SolutionImporter(Problem problem) {
		this.problem = problem;
	}

	public void setSolutionFileName(String sfn) {
		solutionFileName = sfn;
	}

	public Solution readData() {
		solution = new Solution(problem);
		try {
			BufferedReader in = new BufferedReader(new FileReader(
					solutionFileName));
			String str = in.readLine().trim();
			String s[] = str.split("\\s+");
			for (int p_index = 0; p_index < s.length; p_index++) {
				int m_index = Integer.parseInt(s[p_index]);
				solution.assignProcessToMachine(p_index, m_index);
			}
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return solution;
	}

	public Solution getSolution(){
		return solution;
	}
}
